#ifndef _COMMON_H_
#define _COMMON_H_

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <memory>
#include <string>
#include <mutex>
#include <thread>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <deque>
#include <atomic>
#include <mutex>
#include <condition_variable>
#include <math.h>
#include <cmath>
#include <list>
#include <errno.h>
#include <linux/unistd.h>       /* for _syscallX macros/related stuff */
#include <linux/kernel.h>       /* for struct sysinfo */
#include <linux/input.h>
#include <sys/sysinfo.h>
#include <fcntl.h>
#include <termios.h>
#include <netdb.h>
#include <sys/stat.h>
#include <ctype.h>
#include <sys/un.h>
#include <sys/ioctl.h>
#include <linux/netlink.h>
#include "plog/Log.h"
#include "plog/Initializers/RollingFileInitializer.h"
#include "json/json.h"


namespace iecas_ns
{
    #define SRC_DEV "src_dev"
    #define SRC_FD "src_fd"
    #define SRC_DATA "src_data"
    #define DEV_STAT "dev_stat"
    #define DEST_DEV "dest_dev"
    #define TRANS_MESG_TAG "trans_mesg_tag"
    #define TRANS_MESG_DEST "trans_mesg_dest"
    #define TRANS_ORDER_CHG_IN "trans_order_chg_in"
    #define TRANS_ORDER_CHG_MID "trans_order_chg_mid"
    #define TRANS_ORDER_OUT_MID "trans_order_out_mid"
    #define TRANS_ORDER_OUT_CONT "trans_order_out_cont"
    #define TRANS_ORDER_OUT_DEST "trans_order_out_dest"

    using namespace std;
    using namespace Json;

    class CCommon
    {
		public:
			static shared_ptr<CCommon> getInstance();
			void addDataBack(Value data);
            bool getDataFront(Value &data);
            void delDataFront(void);
            void addDev(string dev);
            void addDev(string dev, int fd);
            bool getDevFdStat(string dev, int &fd);
            bool getDevStat(string dev);
            void setDevStat(string dev, bool stat);
            void getDevJson(Value &dev);
            void delDev(string dev);
            void getIpNotSocket(vector<string> &dev);
            bool isIpSocket(string dev);
            void addIpName(string ip, string name);
            void delIpName(void);
            void getIpNameJson(Value &name);
            int64_t getMsTimeStamp(void);
		private:
			static shared_ptr<CCommon> sm_intancePtr;
			CCommon();
			mutex m_dataLock;
            deque<Value> m_data_dq;
            mutex m_dev_fd_stat_Lock;
            map<string, Value> m_dev_fd_stat;
            mutex m_ip_name_lock;
            map<string, string> m_ip_name;
    };
}

#endif
